<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

$request = Yii::$app->getRequest();
$type = $request->get('type', null);
$sort = $request->get('sort', null);
$key = $request->get('key', null);
?>
<style>


	#member .tips li:first-child {
		background: #fe7b9d url("<?= Yii::getAlias('@web/backend/img/member/add_big.png') ?>") 50% 50% no-repeat;
		border: 0;
	}
	.drop {display: none;}
	.tips li:not(:first-child):hover .drop {display: block;}
	.tips label {margin-bottom: 2px;}
	#member .tips li .tips-top .person-phone{height: 25px;}
	.excBtn{
		display: inline-block;
		padding: 0 12px;
		height: 40px;
		line-height: 40px;
		border: 1px solid #e5e5e5;
		color: #6f6f6f;
		text-align: center;
	}
	.list {font-size: 0;}
	.list a{font-size: 15px;margin: 0 20px 20px 0;}
	input[name="key"]{padding-left: 35px;background:url(<?=Yii::getAlias('@web/backend/img/common/search.png');?>) no-repeat 6px center;}
	@media (min-width: 1200px) and (max-width: 1440px){
		#member .tips li:nth-child(4n) {
			 margin-right: 20px;
		}
	}
</style>

<div class="row">
	<div class="container lh30">
		<a class="topNav" href="<?= Url::to(['/system/site/index']) ?>"><img src="<?= Yii::getAlias('@web/backend/img/home/home.png') ?>" alt="首页"/>返回首页</a>
	</div>
</div>

<div class="row borB" style="background-color: #f5f5f5;">
	<div class="container lh30" style="padding-left: 0;">
		<ul class="nav nav-tabs">
			<li class="active"><a href="<?= Url::to(['index']) ?>">会员档案</a></li>
			<li><a href="<?= Url::to(['analysis']) ?>">会员分析</a></li>
		</ul>
	</div>
</div>

<div class="row">

	<div class="container">
		<div id="member" class="member">
			<div class="search-info">
				<form class="mt20" action="" method="get">
					<input class="mr20" type="text" name="key" placeholder="搜索会员名字、手机号" value="<?= $key ?>" style="height: 43px;padding-left: 33px;width: 224px;">

					<input class="lh45 laydate-icon" type="text" placeholder="搜索生日" name="birthday" value="" onclick="laydate()">

					<a  class="btnBg dis text-center lh45 " style="width: 56px; height: 40px;">
						<input  type="submit" value="搜索"  style="display: block; width: 100%; background: 0; border:0;line-height: 45px;">
					</a>
					<a class="btnBg dis text-center lh45 ml20" href="<?= Url::to(['excel', 'key' => $key, 'type' => $type, 'sort' => $sort]) ?>"><img
								src="<?= Yii::getAlias('@web/backend/img/stocks/excel.png'); ?>" alt=""
								style="margin-right: 9px;vertical-align: text-top;"/>导出EXCEL</a>
					<label class="ml20" >排序方式
						<div class="select" style="margin-top: -4px; margin-left: 5px;">
							<?= Html::dropDownList('sort', $request->get('sort'), [
							'dft' => '默认排序',
							'last' => '按未到店时间',
							'consume' => '按累计消费'
							], ['onchange' => 'actionSearch(this)']); ?>
						</div>
					</label>
				</form>

				<div class="list mg20-y">

					<a<?= ($type == 'all' || $type == null) ? ' class="active"' : '' ?> href="<?= Url::to(['index', /*'key' => $key, */'type' => 'all', 'sort' => $sort]) ?>">全部:<?= $totalCountMember ?>人</a>

					<?php foreach($listGrade as $grade): ?>
						<a<?= $type == $grade['config_key'] ? ' class="active"' : '' ?> href="<?= Url::to(['index',/* 'key' => $key,*/ 'type' => $grade['config_key'], 'sort' => $sort]) ?>"><?= $grade['config_key'] ?>:<?= $grade['counts'] ?>人</a>
					<?php endforeach; ?>


				</div>
			</div>

			<div class="tips">
				<ul class="clearfix">
					<li class="first" onclick="location.href='<?= Url::to(['basic']) ?>'" style="cursor:pointer">
						<div><a href="<?= Url::to(['basic']) ?>">添加新会员</a></div>
					</li>

					<?php foreach($list as $member): ?>
					<li>
						<a href="<?= Url::to(['basic', 'id' => $member['member_id']]) ?>">
							<img class="role" src="" alt="用户头像">
							<div class="tips-top">
								<div class="person-name"><?= $member['member_name'] ?>
									<?= $member['member_grade'] ?>
								</div>
								<div class="person-phone"><?= $member['member_mobile'] ?></div>
								<div class="tips-center">
									<div>
										<label>储值卡：<em><?= $member['member_balance'] ?></em></label>
									</div>
									<div>
										<label>欠费：<em><?= $member['member_debt'] ?></em></label>
									</div>
									<div>
										<label>累计消费：<em><?= $member['consume_amount_all'] ?: '0.00' ?></em></label>
									</div>
								</div>
							</div>
							<div class="tips-bottom">
								<div>
									<label>职业：<span><?= $member['member_job'] ?></span></label>
									<label class="pull-right">婚姻：<span><?= $member['marriage'] == 1 ? '已婚' : '未婚' ?></span></label>
								</div>
								<label>生日：<span><?= $member['member_birthday'] ?></span></label>
								<br/>
								<label>住址：<span><?= $member['address'] ?></span></label>
							</div>
							<div class="tips-arrTime clearfix lh30" style="padding-left: 50px;padding-right: 27px;">
								<div class="pull-left"><a class="drop btnSm" href="javascript:;" member_id="<?= $member['member_id'] ?>">作废</a></div>
								<div class="pull-right">已<?= floor((time() - strtotime($member['last_consume_time'])) / 86400) ?>天未到店</div>
							</div>
						</a>
					</li>
					<?php endforeach; ?>
				</ul>
			</div>
			<div class="page">
				<?= LinkPager::widget([
					'pagination' => $page,
					// 'hideOnSinglePage' => true
				]); ?>
			</div>
		</div>
	</div>
</div>

<?php $this->beginBlock('js_end') ?>
function actionSearch(own) {
	var sort = $(own).val();
	if (<?= ($key || $type) ? 1 : 0 ?> == 1) {
		location.href = '<?= Url::to(['index', 'key' => $key, 'type' => $type]) ?>' + '&sort=' + sort;
	} else {
		location.href = '<?= Url::to(['index']) ?>' + '?sort=' + sort;
	}
}
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_end'], $this::POS_END); ?>
<?php $this->registerJsFile("@web/system/member/index.js",['position'=>$this::POS_END]);?>
